<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link href="css/main.css" rel="stylesheet">
</head>
<body>
	<h1>Hello, world!</h1>
	<!-- 当前页面的url -->
	<div id="href"></div>
	<a href="b.html" target="_blank">打开【b.html】</a>
	<!-- websocket状态 -->
	<div id="status"></div>
	<div>
		toCid:<input id="toCid" value="b"/>
		message: <input id="message" value="您好"/>
		<input type="button" value="发送" onclick="send();"/>
	</div>
	<!-- websocket消息日志 -->
	<div id="wsMsg"><br/></div>
</body>
</html>
<script src="js/jquery.3.2.1.min.js"></script>
<script src="../../js/WebSocket.js"></script>
<script>
	//发送消息给某个cid
	function send(){
		sendTo($('#toCid').val(), {message: $('#message').val()});
	}
	$('#href').html(location.href);
	var cid = `index`;
	var wsUrl = `ws://localhost:8081/websocket/${cid}`;
	// 建立WebSocket连接
	createWebSocket(wsUrl);
	// 由各个子系统重写onmessage()方法
	function onmessageHandler(data) {
		/*
		try {
			var json = JSON.parse(data);
			if (json) {
				if (json.message) {
					alert(json.message);
				}
			} else {
				alert('消息格式不是JOSN');
			}
		} catch (err) {
			alert(data);
			console.log(err.message);
		}
		*/
	}
</script>